﻿#ifndef APP_H
#define APP_H

#ifdef __cplusplus
extern "C" {
#endif

#include "app_config.h"
#include "app_anim.h"
#include "utils/lv_anim_timeline_wrapper.h"
#include "utils/lv_obj_ext_func.h"

 /*********************
  *      TYPE
  *********************/
typedef void(*app_load_t)(void*);
typedef void(*app_did_load_t)(void*);
typedef void(*app_will_appear_t)(void*);
typedef void(*app_did_appear_t)(void*);
typedef void(*app_will_disappear_t)(void*);
typedef void(*app_did_disappear_t)(void*);
typedef void(*app_did_unload_t)(void*);

/**
 * @brief 页面状态
*/
typedef enum {
    PAGE_STATE_IDLE,
    PAGE_STATE_LOAD,
    PAGE_STATE_WILL_APPEAR,
    PAGE_STATE_DID_APPEAR,
    PAGE_STATE_ACTIVITY,
    PAGE_STATE_WILL_DISAPPEAR,
    PAGE_STATE_DID_DISAPPEAR,
    PAGE_STATE_UNLOAD,
    _PAGE_STATE_LAST
}app_state_e;

/**
 * @brief 页面回调
*/
typedef struct
{
    app_load_t on_load;
    app_did_load_t on_did_load;
    app_will_appear_t on_will_appear;
    app_did_appear_t on_did_appear;
    app_will_disappear_t on_will_disappear;
    app_did_disappear_t on_did_disappear;
    app_did_unload_t on_did_unload;
}app_ops_t;

/**
 * @brief 页面结构
*/
typedef struct
{
    lv_obj_t*   root;   // UI根节点
    char*       name;   // 页面名称
    uint16_t    id;     // 页面唯一ID
    void*       user_data;  // 用户数据

    app_ops_t*  ops;    // 页面回调

    /* 动画 */
    struct
    {
        bool is_enter;           // Whether it is the entering party
        bool is_busy;            // Whether the animation is playing
        app_anim_attr_t attr;        // Animation properties
    } anim;

    /* 状态 */
    app_state_e state;
}app_page_t;

/*********************
 *      Function
 *********************/
void app_init();
void app_switch_by_index(uint8_t index);
void app_switch_by_page(app_page_t* page);
void app_switch_by_name(const char* name);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif
